<?php
require_once '../include/config.php';
require_once '../include/utils.class.php';
require_once '../include/orm.class.php';
require_once 'meta.php';

$directory = Utils::get_param('d', NULL);
$file = Utils::get_param('f', NULL);
$method = Utils::get_param('m', NULL);
$session_id = Utils::get_param('PHPSESSID', NULL);

if ($session_id) {
  session_id($session_id);
  session_start();
} else {
  session_name(SESSION);
  session_start();
}

if (!$directory || !$file || !$method) {
  die('Illegal parameters');
}

if (!in_array($directory, unserialize(EXCEPTIONS)) && !isset($_SESSION[IS_AUTHENTICATED])) {
  die('Not Authenticated');
}

require_once dirname(__FILE__) . "/src/$directory/$file.srv.php";
$orm = new ORM();
$orm->begin();
Server::$method($orm);
$orm->commit();
$orm->close();
?>